

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<script type="text/javascript" src="helpman_topicinit.js"></script>

<title>Object Oriented Programming In C [Enterprise Architect User Guide]</title>

<meta name="keywords" content="Enterprise Architect, Sparx Systems, UML, C,C Object Oriented Programmiing,C Modeling Conventions,Modeling Conventions,Modeling Conventions C, Object Oriented Programming,Modeling Conventions Object Oriented Programming in C,Object Oriented Programming,Object Oriented Programming C Code Generation For UML Model,Object Oriented Programming Limitations">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta http-equiv="Content-Style-Type" content="text/css" />

<link type="text/css" href="default.css" rel="stylesheet" />
<style type="text/css">
  A, A:Visited
  {
    color: #00F;
  }

  A:Active, A:Hover
  {
    color: #F00;
  }

  OL
  {
    margin: 5px 0 5px 48px;
  }

  UL
  {
    margin-bottom: 3px;
    margin-top: 0;
  }

  #nsr
  {
    background-color: #D4DFFF;
  }

  #nsr A
  {
    text-decoration: none;
  }

  #mainbody
  {
    padding: 8px;
  }

  .p_BodyText
  {
    padding: 5px 0;
  }
</style>



<style type="text/css" media="screen">
  BODY
  {
    background-color: #FFFFFF;
  }

  #nsr
  {
    padding: 6px 6px 0 6px;
    border-bottom: none;
    vertical-align: top;
    z-index: 2;
    visibility: visible;
    left: 0;
    top: 0;
    position: absolute;
  }

  #mainbody
  {
    left: 0;
    top: 0;
    margin: 0;
    position: absolute;
    padding: 10px;
    overflow: auto;
    height: 100%;
    z-index: 1;
    background-repeat: no-repeat;
    background-position: bottom right;
    background-attachment: fixed;
  }
</style>

<style type="text/css" media="print">
  #nsr
  {
    visibility: none;
  }

  #mainbody
  {
    overflow: visible;
  }
</style>
<script type="text/javascript" language="JavaScript" src="nonscroll.js"></script>

</head>
<body scroll="no">

<div id="page">



        <div id="content">
          <div id="content-inner">
          



  
          <div id="nsr">
            <table border="0" cellspacing="0" cellpadding="4" width="100%">
              <tr valign="top">
                <td align="left">
  


                  <p class="p_Heading1"><span class="f_Heading1">Object Oriented Programming In C</span></p>



  
                </td>
                <td align="right">
                  <a href="introduction.htm" onmouseover="document.images.main.src='button_main_h.gif'" onmouseout="document.images.main.src='button_main.gif'">
                    <img name="main" src="button_main.gif" border=0 alt="Return to Introduction">
                  </a>&nbsp;
    
                  <a href="c_conventions.htm" onmouseover="document.images.prev.src='button_prev_h.gif'" onmouseout="document.images.prev.src='button_prev.gif'">
                    <img name=prev src="button_prev.gif" border=0 alt="Previous page" />
                  </a>&nbsp;
    
    
    
                  <a href="csharp_conventions.htm" onmouseover="document.images.next.src='button_next_h.gif'" onmouseout="document.images.next.src='button_next.gif'">
                    <img name=next src="button_next.gif" border=0 alt="Next page" />
                  </a>
    
    
                </td>
              </tr>
            </table>
          </div>
          <div id="mainbody">
  


                <p class="p_BodyText"><span class="f_BodyText">The following conventions are used for Object-Oriented programming in C.</span></p>
<p class="p_BodyText"><span class="f_BodyText">To configure Enterprise Architect to support Object-Oriented programming using C, you must set the </span><span class="f_MenuKeyField">Object Oriented Support</span><span class="f_BodyText"> option to </span><span class="f_MenuKeyField">True</span><span class="f_BodyText"> on </span><span class="f_BodyText">the </span><span class="f_UIControl"><a href="options___c.htm">C Specifications</a></span><span class="f_BodyText"> page of the </span><span class="f_UIControl">Options</span><span class="f_BodyText"> dialog</span><span class="f_BodyText">.</span></p>
<p class="p_SubHeadingL1"><span class="f_SubHeadingL1">Stereotype</span></p>
<div style="text-align: left; text-indent: 0px; padding: 0px 0px 0px 0px; margin: 5px 0px 5px 13px;"><table cellspacing="0" cellpadding="0" border="0" style="border: none; border-spacing:0px; border-collapse: collapse;">
<tr style="text-align:left;vertical-align:top;">
<td valign="top" width="106" bgcolor="#e3e6ed" style="width:106px; background-color:#e3e6ed; border: solid 1px #000000;"><p class="p_Tableheader"><span class="f_Tableheader">Stereotype</span></p>
</td>
<td valign="top" width="221" bgcolor="#e3e6ed" style="width:221px; background-color:#e3e6ed; border: solid 1px #000000;"><p class="p_Tableheader"><span class="f_Tableheader">Applies To</span></p>
</td>
<td valign="top" width="361" bgcolor="#e3e6ed" style="width:361px; background-color:#e3e6ed; border: solid 1px #000000;"><p class="p_Tableheader"><span class="f_Tableheader">Corresponds To</span></p>
</td>
</tr>
<tr style="text-align:left;vertical-align:top;">
<td valign="top" width="106" style="width:106px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext" style="font-weight: bold;">enumeration</span></p>
</td>
<td valign="top" width="221" style="width:221px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext">Class</span></p>
</td>
<td valign="top" width="361" style="width:361px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext">An </span><span class="f_Tabletext" style="font-style: italic;">enum</span><span class="f_Tabletext"> type.</span></p>
</td>
</tr>
<tr style="text-align:left;vertical-align:top;">
<td valign="top" width="106" style="width:106px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext" style="font-weight: bold;">struct</span></p>
</td>
<td valign="top" width="221" style="width:221px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext">Class</span></p>
</td>
<td valign="top" width="361" style="width:361px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext">A </span><span class="f_Tabletext" style="font-style: italic;">struct</span><span class="f_Tabletext"> type.</span></p>
</td>
</tr>
<tr style="text-align:left;vertical-align:top;">
<td valign="top" width="106" style="width:106px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext" style="font-weight: bold;">&nbsp;</span></p>
</td>
<td valign="top" width="221" style="width:221px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext">Attribute</span></p>
</td>
<td valign="top" width="361" style="width:361px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext">A keyword </span><span class="f_Tabletext" style="font-style: italic;">struct</span><span class="f_Tabletext"> in variable definition.</span></p>
</td>
</tr>
<tr style="text-align:left;vertical-align:top;">
<td valign="top" width="106" style="width:106px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext" style="font-weight: bold;">typedef</span></p>
</td>
<td valign="top" width="221" style="width:221px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext">Class</span></p>
</td>
<td valign="top" width="361" style="width:361px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext">A </span><span class="f_Tabletext" style="font-style: italic;">typedef</span><span class="f_Tabletext"> statement, where the parent is the original type name.</span></p>
</td>
</tr>
<tr style="text-align:left;vertical-align:top;">
<td valign="top" width="106" style="width:106px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext" style="font-weight: bold;">union</span></p>
</td>
<td valign="top" width="221" style="width:221px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext">Class</span></p>
</td>
<td valign="top" width="361" style="width:361px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext">A </span><span class="f_Tabletext" style="font-style: italic;">union</span><span class="f_Tabletext"> type.</span></p>
</td>
</tr>
<tr style="text-align:left;vertical-align:top;">
<td valign="top" width="106" style="width:106px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext" style="font-weight: bold;">&nbsp;</span></p>
</td>
<td valign="top" width="221" style="width:221px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext">Attribute</span></p>
</td>
<td valign="top" width="361" style="width:361px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext">A keyword </span><span class="f_Tabletext" style="font-style: italic;">union</span><span class="f_Tabletext"> in variable definition.</span></p>
</td>
</tr>
</table>
</div>
<p class="p_SubHeadingL1"><span class="f_SubHeadingL1">Tagged Values</span></p>
<div style="text-align: left; text-indent: 0px; padding: 0px 0px 0px 0px; margin: 5px 0px 5px 13px;"><table cellspacing="0" cellpadding="0" border="0" style="border: none; border-spacing:0px; border-collapse: collapse;">
<tr style="text-align:left;vertical-align:top;">
<td valign="top" width="106" bgcolor="#e3e6ed" style="width:106px; background-color:#e3e6ed; border: solid 1px #000000;"><p class="p_Tableheader"><span class="f_Tableheader">Tag</span></p>
</td>
<td valign="top" width="221" bgcolor="#e3e6ed" style="width:221px; background-color:#e3e6ed; border: solid 1px #000000;"><p class="p_Tableheader"><span class="f_Tableheader">Applies To</span></p>
</td>
<td valign="top" width="360" bgcolor="#e3e6ed" style="width:360px; background-color:#e3e6ed; border: solid 1px #000000;"><p class="p_Tableheader"><span class="f_Tableheader">Corresponds To</span></p>
</td>
</tr>
<tr style="text-align:left;vertical-align:top;">
<td valign="top" width="106" style="width:106px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext" style="font-weight: bold;">anonymous</span></p>
</td>
<td valign="top" width="221" style="width:221px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext">Class with stereotype of </span><span class="f_Tabletext" style="font-style: italic;">enumeration</span><span class="f_Tabletext">, </span><span class="f_Tabletext" style="font-style: italic;">struct</span><span class="f_Tabletext"> or </span><span class="f_Tabletext" style="font-style: italic;">union</span><span class="f_Tabletext">.</span></p>
</td>
<td valign="top" width="360" style="width:360px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext">The name of this Class being defined only by the </span><span class="f_Tabletext" style="font-style: italic;">typedef</span><span class="f_Tabletext"> statement.</span></p>
</td>
</tr>
<tr style="text-align:left;vertical-align:top;">
<td valign="top" width="106" style="width:106px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext" style="font-weight: bold;">bodyLocation</span></p>
</td>
<td valign="top" width="221" style="width:221px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext">Operation</span></p>
</td>
<td valign="top" width="360" style="width:360px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext">The location the method body is generated to. Expected values are </span><span class="f_MenuKeyField">header</span><span class="f_Tabletext">,</span><span class="f_MenuKeyField"> classDec</span><span class="f_Tabletext"> or </span><span class="f_MenuKeyField">classBody.</span></p>
</td>
</tr>
<tr style="text-align:left;vertical-align:top;">
<td valign="top" width="106" style="width:106px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext" style="font-weight: bold;">define</span></p>
</td>
<td valign="top" width="221" style="width:221px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext">Attribute</span></p>
</td>
<td valign="top" width="360" style="width:360px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext" style="font-style: italic;">#define</span><span class="f_Tabletext"> statement.</span></p>
</td>
</tr>
<tr style="text-align:left;vertical-align:top;">
<td valign="top" width="106" style="width:106px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext" style="font-weight: bold;">typedef</span></p>
</td>
<td valign="top" width="221" style="width:221px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext">Class with stereotype of </span><span class="f_Tabletext" style="font-style: italic;">enumeration</span><span class="f_Tabletext">, </span><span class="f_Tabletext" style="font-style: italic;">struct</span><span class="f_Tabletext"> or </span><span class="f_Tabletext" style="font-style: italic;">union</span><span class="f_Tabletext">.</span></p>
</td>
<td valign="top" width="360" style="width:360px; border: solid 1px #000000;"><p class="p_Tabletext"><span class="f_Tabletext">This Class being defined in a </span><span class="f_Tabletext" style="font-style: italic;">typedef</span><span class="f_Tabletext"> statement.</span></p>
</td>
</tr>
</table>
</div>
<p class="p_SubHeadingL1"><span class="f_SubHeadingL1">Object-Oriented C Code Generation for UML Model</span></p>
<p class="p_BodyText"><span class="f_BodyText">The basic idea of implementing a UML Class in C code is to group the data variable (UML attributes) into a structure type. This structure is defined in a </span><span class="f_BodyText" style="font-weight: bold;">.h</span><span class="f_BodyText"> file so that it can be shared by other classes and by the client that referred to it.</span></p>
<p class="p_BodyText"><span class="f_BodyText">An operation in a UML Class is implemented in C code as a function. The name of the function must be a fully qualified name that consists of the operation name, as well as the Class name to indicate that the operation is for that Class. A delimiter (specified in the </span><span class="f_MenuKeyField">Namespace Delimiter</span><span class="f_BodyText"> option on the </span><span class="f_UIControl"><a href="options___c.htm">C Specifications</a></span><span class="f_BodyText"> page) is used to join the Class name and function (operation) name.</span></p>
<p class="p_BodyText"><span class="f_BodyText">The function in C code must also have a reference parameter to the Class object. You can modify the </span><span class="f_MenuKeyField">Reference as Operation Parameter</span><span class="f_BodyText">, </span><span class="f_MenuKeyField">Reference Parameter Style</span><span class="f_BodyText"> and </span><span class="f_MenuKeyField">Reference Parameter Name</span><span class="f_BodyText"> options on the </span><span class="f_UIControl">C Specifications</span><span class="f_BodyText"> page to support this reference parameter.</span></p>
<p class="p_SubHeadingL1"><span class="f_SubHeadingL1">Limitations of Object-Oriented Programming in C</span></p>
<ol style="text-indent: 0px; margin-left: 48px; list-style-position: outside;">
<li value=1><span class="f_NumberedList">No scope mapping for an attribute: an attribute in a UML Class is mapped to a structure variable in C code, and its scope (private, protected or public) is ignored.</span></li>
<li value=2><span class="f_NumberedList">Currently an inner Class is ignored: if a UML Class is the inner Class of another UML Class, it is ignored when generating C code.</span></li>
<li value=3><span class="f_NumberedList">Initial value is ignored: the initial value of an attribute in a UML Class is ignored in generated C code.</span></li>
</ol>
<p class="p_SeeAlso"><span class="f_SeeAlso">See Also</span></p>
<ul style="text-indent: 0px; margin-left: 30px; list-style-position: outside;">
<li><span class="f_Bulletlist1"><a href="o316.htm">Import Source Code</a></span></li>
<li><span class="f_Bulletlist1"><a href="generatesourcecode.htm">Generate Source Code</a></span></li>
<li><span class="f_Bulletlist1"><a href="options___c.htm">C Options</a></span></li>
</ul>




            </div>
          </div>
        </div>



</div>


</body>
</html>
